﻿using AutoMapper;
using Microsoft.EntityFrameworkCore;
using QMERP.Domain.Dtos;
using QMERP.Infrastructure.EFCore;

namespace QMERP.Application.Services
{
    public class SalesProcessService : ISalesProcessService
    {
        private readonly IMapper _mapper;
        //private readonly ICache _cache;
        private readonly QMERPDbContext _db;
        public SalesProcessService(IMapper mapper, QMERPDbContext db)
        {
            _mapper = mapper;
            _db = db;
        }
        /// <summary>
        /// 获取code的工序集合
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public async Task<List<SalesProcessResponse>> GetByValue(string code)
        {
            var list = await _db.SalesProcess.Where(x => x.Code == code).ToListAsync();
            return _mapper.Map<List<SalesProcessResponse>>(list);
        }
        /// <summary>
        /// 获取销售工序列表基础数据
        /// </summary>
        /// <returns></returns>
        public async Task<List<SalesProcessResponse>> GetBasicSalesProcesses()
        {
            var list = await _db.SalesProcess.Where(x => x.IsKCUsable).ToListAsync();
            return _mapper.Map<List<SalesProcessResponse>>(list);
        }
    }
}
